﻿<template>
    <elm-page-bb>
        <el-form ref="model" :model="model" label-width="120px" size="small">
            <el-form-item label="分类" prop="dict_type" :rules="[{ required: true, message: '分类必须填写'}]">
                <elm-select url="/system/dict/type/GetData" v-model="model.dict_type"
                            placeholder="请选择" style="width: 100%"
                            key-name="id" label-name="dict_name" value-name="dict_type">
                </elm-select>
            </el-form-item>
            <el-form-item label="字典标签" prop="dict_label" :rules="[{ required: true, message: '字典标签必须填写'}]">
                <el-input v-model="model.dict_label" type="dict_label"></el-input>
            </el-form-item>
            <el-form-item label="字典值" prop="dict_value" :rules="[{ required: true, message: '字典值必须填写'}]">
                <el-input v-model="model.dict_value" type="dict_value"></el-input>
            </el-form-item>
            <el-form-item label="字典排序" prop="dict_sort" :rules="[{ required: true, message: '字典排序必须填写'}]">
                <el-input-number v-model="model.dict_sort" :min="0" type="dict_sort" style="width: 100%"/>
            </el-form-item>
            <el-form-item label="状态" prop="status" :rules="[{ required: true, message: '状态必须选择'}]">
                <el-radio-group v-model="model.status">
                    <el-radio
                        v-for="dict in dict_status"
                        :key="dict.value"
                        :label="dict.value"
                    >{{dict.label}}</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="是否默认" prop="is_default" :rules="[{ required: true, message: '是否默认必须选择'}]">
                <el-radio-group v-model="model.is_default">
                    <el-radio
                        v-for="dict in dict_is_default"
                        :key="dict.value"
                        :label="dict.value"
                    >{{dict.label}}</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="备注" prop="remark">
                <el-input v-model="model.remark" type="textarea" placeholder="请输入内容"></el-input>
            </el-form-item>
        </el-form>
        <template #bottom>
            <el-button type="success" size="small" @click="submit">立即保存</el-button>
            <el-button size="small" @click="close">取消</el-button>
        </template>
    </elm-page-bb>
</template>

<script>
    export default {
        extends: elmVueBase,
        data() {
            return {
                model: {
                    dict_type: null,
                    dict_label: null,
                    dict_value: null,
                    dict_sort: 0,
                    status: '0',
                    is_default: 'Y',
                    remark: null,
                },
                dict_status: [{value: '0', label: '正常'},{value: '1', label: '停用'}],
                dict_is_default: [{value: 'Y', label: '是'},{value: 'N', label: '否'}],
            }
        },
        created() {
        },
        methods: {
          async submit() {
            var res = await elm.post("/system/dict/Upsert", this.model);
            if (res > 0) {
              this.v('保存成功。')
              this.close();
              this.request.callVue.tablebinding();
            } else {
              this.error('保存失败，请稍后尝试。');
            }

          }
        }
    }
</script>

<style scoped>
</style>